package com.mtl.inmigrant.shoes;

import java.io.IOException;

import android.app.Activity;
import android.app.ListActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import com.mtl.inmigrant.shoes.entity.ShoeActionsInmigrant;
import com.mtl.inmigrant.shoes.sqlite.ShoesDataSource;

public class ActivityMtlInmigrantShoesAct extends Activity {
	
	private ShoesDataSource dataSource;
	private SharedPreferences prefs;
	
	   @Override
	    public void onCreate(Bundle savedInstanceState) {   
		   
		    super.onCreate(savedInstanceState);    	
		    setContentView(R.layout.activity_main);
		    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
		    if (android.os.Build.VERSION.SDK_INT > 9) {
		        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		        StrictMode.setThreadPolicy(policy);
		      }		    
			dataSource = new ShoesDataSource(this);
			dataSource.open();
			
			//List<ShoeActionsInmigrant> values = dataSource.getAllShoesActions();
			
			/*if (values.size() > 0){			
			// Use the SimpleCursorAdapter to show the elements in a ListView
				ArrayAdapter<ShoeActionsInmigrant> adapter = new ArrayAdapter<ShoeActionsInmigrant>(this,
							android.R.layout.simple_list_item_1, values);			
				setListAdapter(adapter);
			}*/
			
			dataSource.close();
		   
	   }
	   
	   
	   
	// Will be called via the onClick attribute
	 		// of the buttons in main.xml
	 		public void onClick(View view) throws IOException {
	 			
	 			@SuppressWarnings("unchecked")
	 			//ArrayAdapter<ShoeActionsInmigrant> adapter = (ArrayAdapter<ShoeActionsInmigrant>) getListAdapter();
	 			ShoeActionsInmigrant shoeAction = null ;
	 			ActionShoeActivityHelper actionShoeActivityHelper = new ActionShoeActivityHelper();
	 			dataSource.open();
	 			
	 			switch (view.getId()) {
	 			case R.id.addActivity:
	 				// Save the new comment to the database
	 				Toast.makeText(this, "Get all acitivities from page Google+",
							Toast.LENGTH_LONG).show();
	 				
	 				
	 				shoeAction  = new ShoeActionsInmigrant(); 
	 				
	 				if(!actionShoeActivityHelper.hasUserLoadTables(dataSource)){
	 					actionShoeActivityHelper.loadTablesUsignInfoPage(dataSource, prefs);
	 					
	 				}else{
	 					//actionShoeActivityHelper.compareTablesAndPage(dataSource, prefs);
	 				}

	 				
	 				break;
	 				case R.id.deleteActivity:
	 					Toast.makeText(this, "Delete all current activities",
								Toast.LENGTH_LONG).show();
	 					dataSource.deleteAllShoeAction();
	 					//adapter.clear();
	 				break;
	 				case R.id.syncronized:
	 					Toast.makeText(this, "An update from the page google+",
								Toast.LENGTH_LONG).show();
	 					actionShoeActivityHelper.compareTablesAndPage(dataSource, prefs);
	 					//adapter.clear();
	 				break;

	 			}
	 			//adapter.notifyDataSetChanged();
	 			dataSource.close();	 			
	 		}
	 			
	 	
	
	 			
	 		
}
